﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using WinampFrontEndLib;
using ForfiterAmp.Entities;
using System.ServiceModel;

namespace ForfiterAmp.WebService
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WinAmpService : System.Web.Services.WebService
    {
        private const string PAUSE_STRING = "Wstrzymane";
        private const string STOP_STRING = "Zatrzymane";

        [WebMethod]
        public string HelloWorld()
        {
            return "trolololo";
        }

        [WebMethod]
        public PlayerState GetPlayerState()
        {
            PlayerState playerState = new PlayerState();
            playerState.SongState = new SongState();
            playerState.SongState.CurrentSong = new Song();
            var state = WinampLib.GetCurrentSongTitle();

            if (state == PAUSE_STRING)
                playerState.PlaybackState = PlaybackState.Paused;
            else if (state == STOP_STRING)
                playerState.PlaybackState = PlaybackState.Stopped;
            else
            {
                playerState.PlaybackState = PlaybackState.Playing;
                playerState.SongState.CurrentSong.Title = state;
            }

            return playerState;
        }

        [WebMethod]
        public void Pause() { WinampLib.Pause(); }

        [WebMethod]
        public void Play() { WinampLib.Play(); }

        [WebMethod]
        public void Stop() { WinampLib.Stop(); }

        [WebMethod]
        public void NextTrack() { WinampLib.NextTrack(); }

        [WebMethod]
        public void PreviousTrack() { WinampLib.PrevTrack(); }

        [WebMethod]
        public void VolumeUp() { WinampLib.VolumeUp(); }

        [WebMethod]
        public void VolumeDown() { WinampLib.VolumeDown(); }
    }
}